﻿using Common;
using MVP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinForms
{
    public partial class AktivasiForm : Form, IAktivasiView
    {
        private AktivasiPresenter _presenter;
        public AktivasiPresenter Presenter 
        {
            get { return _presenter; } 
        }
        public AktivasiForm()
        {
            _presenter = new AktivasiPresenter(this);
            InitializeComponent();
            Initialize(null, new EventArgs());
        }

        #region IAktivasiView Members

        public string ProductNumber
        {
            get
            {
                return productNumberTextBox.Text;
            }
            set
            {
                productNumberTextBox.Text = value;
            }
        }

        public string ActivationCode
        {
            get
            {
                return activationCodeTextBox.Text;
            }
            set
            {
                activationCodeTextBox.Text = value;
                activateButton.Enabled = false;
                infoTextBox.Text = "Aktivasi valid.";
            }
        }

        public event EventHandler Save;

        public void SendMessageInfo(string strMessage)
        {
            MessageBox.Show(strMessage);
        }

        public event EventHandler Initialize;

        #endregion IAktivasiView Members


        private void activationCodeTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
        }

        public static class AktivasiDialogBox
        {
            public static bool Show()
            {
                AktivasiForm form = new AktivasiForm();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    return form.Presenter.Activate(form.productNumberTextBox.Text, form.activationCodeTextBox.Text);
                }
                return false;
            }
        }
    }
}
